package com.oocl.zero.datahandle.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.oocl.zero.datahandle.entity.Customer;

public class CustomerFilter {




	/**
	 * input format:id(1) name(2) email(3) gender(4) birthday(5)
	 * @param map
	 * @return true(isFiltered)
	 */
	public static boolean isFiltered(Map<Integer, String> map){
		//check 
		if(map==null || map.size()!=5){
			return true;
		}
		return !(filterId(map.get(1)) && filterEmail(map.get(3)) && filterGender(map.get(4)) && filterDate(map.get(5)));
	}

	
	public static void main(String[] args) {
		
		System.out.println( filterId("012") );
		System.out.println( filterId("0as12") );
		System.out.println( filterId("as") );
		
//		System.out.println( filterEmail("john@163.com") );
//		System.out.println( filterEmail("johndfm") );
//		System.out.println( filterEmail("john@16") );
		
//		System.out.println( filterGender("john@16") );
//		System.out.println( filterGender("true") );
//		System.out.println( filterGender("false") );
		
//		String input="8 john john@163.com true			 1999-10-2";
//		Parser parser = new ParserImpl();
//		parser.doParse(input);
//		Map<Integer, String> map = parser.getDataMap();
		
	}

	private static boolean filterDate(String content) {
		DateFormat df=new SimpleDateFormat(Customer.DATE_FORMAT);
		try {
			df.parse(content);
		} catch (ParseException e) {
			return false;
		}
		return true;
	}
	private static boolean filterGender(String content) {
		Pattern p=Pattern.compile(Customer.GENDER_REGEX);
		Matcher m = p.matcher(content);
		return m.matches();
	}
	private static boolean filterEmail(String content) {
		Pattern p=Pattern.compile(Customer.EMAIL_REGEX);
		Matcher m = p.matcher(content);
		return m.matches();
	}
	private static boolean filterId(String content) {
		 Pattern p=Pattern.compile(Customer.ID_REGEX);
		 Matcher m = p.matcher(content);
		 return m.matches();
	}
}
